package com.wilmer.paperResults.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wilmer.paperAnswers.service.IYwPaperStudentAnswersService;
import com.wilmer.paperResults.domain.YwPaperResultsVO;
import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wilmer.common.annotation.Log;
import com.wilmer.common.core.controller.BaseController;
import com.wilmer.common.core.domain.AjaxResult;
import com.wilmer.common.enums.BusinessType;
import com.wilmer.paperResults.domain.YwPaperResults;
import com.wilmer.paperResults.service.IYwPaperResultsService;
import com.wilmer.common.utils.poi.ExcelUtil;
import com.wilmer.common.core.page.TableDataInfo;

/**
 * 考试成绩Controller
 *
 * @author zl
 * @date 2024-04-23
 */
@RestController
@RequestMapping("/paperResults/paperResults")
public class YwPaperResultsController extends BaseController {
    @Autowired
    private IYwPaperResultsService ywPaperResultsService;
    @Autowired
    private IYwPaperStudentAnswersService ywPaperStudentAnswersService;

    @ApiOperation("查看个人考试列表")
    @GetMapping({"/selectPapersByUserId"})
    public TableDataInfo selectPapersByUserId(YwPaperResults ywPaperResults) {
        this.startPage();
        List<YwPaperResults> ywPaperResults1 = this.ywPaperResultsService.selectPapersByUserId(ywPaperResults);
        return this.getDataTable(ywPaperResults1);
    }

    @ApiOperation("提交考试")
    @PostMapping({"/submitTest"})
    public AjaxResult submitTest(@RequestBody YwPaperResultsVO ywPaperResultsVO) {
        return this.success(this.ywPaperResultsService.submitTest(ywPaperResultsVO));
    }

    //    @ApiOperation("查看试卷详情（考之后)")
//    @GetMapping({"/getInfoBack/{paperId}"})
//    public AjaxResult getInfoBack(@PathVariable Long paperId) {
//        return this.success(this.ywPaperStudentAnswersService.getInfoBack(paperId));
//    }
    @ApiOperation("查看试卷详情（考之后)")
    @GetMapping({"/getInfoBack"})
    public AjaxResult getInfoBack(@Param("paperId") Long paperId,@Param("userId") Long userId) {
        return this.success(this.ywPaperStudentAnswersService.getInfoBack(paperId,userId));
    }

    //    @PreAuthorize("@ss.hasPermi('paperResults:paperResults:list')")
    @GetMapping({"/list"})
    public TableDataInfo list(YwPaperResults ywPaperResults) {
        this.startPage();
        List<YwPaperResults> list = this.ywPaperResultsService.selectYwPaperResultsList(ywPaperResults);
        return this.getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('paperResults:paperResults:export')")
    @Log(
            title = "考试成绩",
            businessType = BusinessType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, YwPaperResults ywPaperResults) {
        List<YwPaperResults> list = this.ywPaperResultsService.selectYwPaperResultsList(ywPaperResults);
        ExcelUtil<YwPaperResults> util = new ExcelUtil(YwPaperResults.class);
        util.exportExcel(response, list, "考试成绩数据");
    }

    @PreAuthorize("@ss.hasPermi('paperResults:paperResults:query')")
    @GetMapping({"/{resultId}"})
    public AjaxResult getInfo(@PathVariable("resultId") Long resultId) {
        return this.success(this.ywPaperResultsService.selectYwPaperResultsByResultId(resultId));
    }

    @PreAuthorize("@ss.hasPermi('paperResults:paperResults:add')")
    @Log(
            title = "考试成绩",
            businessType = BusinessType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody YwPaperResults ywPaperResults) {
        return this.toAjax(this.ywPaperResultsService.insertYwPaperResults(ywPaperResults));
    }

    @PreAuthorize("@ss.hasPermi('paperResults:paperResults:edit')")
    @Log(
            title = "考试成绩",
            businessType = BusinessType.UPDATE
    )
    @PutMapping
    public AjaxResult edit(@RequestBody YwPaperResults ywPaperResults) {
        return this.toAjax(this.ywPaperResultsService.updateYwPaperResults(ywPaperResults));
    }

    @PreAuthorize("@ss.hasPermi('paperResults:paperResults:remove')")
    @Log(
            title = "考试成绩",
            businessType = BusinessType.DELETE
    )
    @DeleteMapping({"/{resultIds}"})
    public AjaxResult remove(@PathVariable Long[] resultIds) {
        return this.toAjax(this.ywPaperResultsService.deleteYwPaperResultsByResultIds(resultIds));
    }
//    /**
//     * 查询考试成绩列表
//     */
//    @PreAuthorize("@ss.hasPermi('paperResults:paperResults:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(YwPaperResults ywPaperResults)
//    {
//        startPage();
//        List<YwPaperResults> list = ywPaperResultsService.selectYwPaperResultsList(ywPaperResults);
//        return getDataTable(list);
//    }
//
//    /**
//     * 导出考试成绩列表
//     */
//    @PreAuthorize("@ss.hasPermi('paperResults:paperResults:export')")
//    @Log(title = "考试成绩", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, YwPaperResults ywPaperResults)
//    {
//        List<YwPaperResults> list = ywPaperResultsService.selectYwPaperResultsList(ywPaperResults);
//        ExcelUtil<YwPaperResults> util = new ExcelUtil<YwPaperResults>(YwPaperResults.class);
//        util.exportExcel(response, list, "考试成绩数据");
//    }
//
//    /**
//     * 获取考试成绩详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('paperResults:paperResults:query')")
//    @GetMapping(value = "/{resultId}")
//    public AjaxResult getInfo(@PathVariable("resultId") Long resultId)
//    {
//        return success(ywPaperResultsService.selectYwPaperResultsByResultId(resultId));
//    }
//
//    /**
//     * 新增考试成绩
//     */
//    @PreAuthorize("@ss.hasPermi('paperResults:paperResults:add')")
//    @Log(title = "考试成绩", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody YwPaperResults ywPaperResults)
//    {
//        return toAjax(ywPaperResultsService.insertYwPaperResults(ywPaperResults));
//    }
//
//    /**
//     * 修改考试成绩
//     */
//    @PreAuthorize("@ss.hasPermi('paperResults:paperResults:edit')")
//    @Log(title = "考试成绩", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody YwPaperResults ywPaperResults)
//    {
//        return toAjax(ywPaperResultsService.updateYwPaperResults(ywPaperResults));
//    }
//
//    /**
//     * 删除考试成绩
//     */
//    @PreAuthorize("@ss.hasPermi('paperResults:paperResults:remove')")
//    @Log(title = "考试成绩", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{resultIds}")
//    public AjaxResult remove(@PathVariable Long[] resultIds)
//    {
//        return toAjax(ywPaperResultsService.deleteYwPaperResultsByResultIds(resultIds));
//    }
}
